package com.hibernate.rcache;

import com.hibernate.rcache.region.RcacheCollectionRegion;
import com.hibernate.rcache.region.RcacheEntityRegion;
import com.hibernate.rcache.strategy.NonStrictReadWriteRcacheEntityRegionAccessStrategy;
import com.hibernate.rcache.strategy.ReadOnlyRcacheEntityRegionAccessStrategy;

import com.hibernate.rcache.strategy.ReadWriteRcacheEntityRegionAccessStrategy;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;

public class RcacheAccessStrategyFactory {


    public EntityRegionAccessStrategy createEntityRegionAccessStrategy(RcacheEntityRegion rcacheEntityRegion, AccessType accessType) {
        switch ( accessType ) {
            case READ_ONLY:

                return  new ReadOnlyRcacheEntityRegionAccessStrategy( rcacheEntityRegion, rcacheEntityRegion.getSettings());
            case READ_WRITE:
                return new ReadWriteRcacheEntityRegionAccessStrategy( rcacheEntityRegion, rcacheEntityRegion.getSettings() );

            case NONSTRICT_READ_WRITE:
                return new NonStrictReadWriteRcacheEntityRegionAccessStrategy(
                        rcacheEntityRegion,
                        rcacheEntityRegion.getSettings()
                );


            default:
                throw new IllegalArgumentException( "unrecognized access strategy type [" + accessType + "]" );

        }
    }

    public CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(RcacheCollectionRegion rcacheCollectionRegion, AccessType accessType) {
        return null;
    }
}
